package com.goldsign.pay.web.portal.controller;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.goldsign.pay.feign.api.sample.facade.SampleFacade;
import com.goldsign.pay.web.portal.feign.sample.facade.LocalSampleService;

import java.util.Date;


@RefreshScope
@RestController
@RequestMapping("order")
public class OrderController {
	
    private static final Logger LOGGER = LoggerFactory.getLogger(OrderController.class);
    
    @Value("${info.name}")
    private String name;
    
    @Autowired
    private LocalSampleService localSampleService;

    @Autowired
    private SampleFacade sampleFacade;
    
    
    @RequestMapping("")
    public String index() {
    	LOGGER.info("configuration name :{}" , name);
    	return "Hello, welcome to g.d.pay webportal! current time: " + new Date().getTime();
    }
    
    
    @RequestMapping("/lists")
    public String list_self(@RequestParam("id")  String id) {
    	LOGGER.info("configuration name :{}" , name);
    	
    	String msg = localSampleService.list(id);
    	System.out.println("request from feign:" + msg) ;
    	return String.format("order list : %s，  current time: %s , config-name:%s", msg , new Date().getTime(),name);
    }
    
    @RequestMapping("/tests")
    public String test_self(@RequestParam("id")  String id) {
    	LOGGER.info("configuration name :{}" , name);
    	
    	String msg = localSampleService.test(id);
    	System.out.println("request from feign:" + msg) ;
    	return String.format("order test : %s，  current time: %s , config-name:%s", msg , new Date().getTime(),name);
    }
    
    
    
    @RequestMapping("/list")
    public String list(@RequestParam("id")  String id) {
    	LOGGER.info("configuration name :{}" , name);
    	
    	String msg = sampleFacade.list(id);
    	System.out.println("request from feign:" + msg) ; 
    	return String.format("order list : %s，  current time: %s , config-name:%s", msg , new Date().getTime(),name);
    }
    
    @RequestMapping("/test")
    public String test(@RequestParam("id")  String id) {
    	LOGGER.info("configuration name :{}" , name);
    	
    	String msg = sampleFacade.test(id);
    	System.out.println("request from feign:" + msg) ;
    	return String.format("order test : %s，  current time: %s , config-name:%s", msg , new Date().getTime(),name);
    }
    
}